<template>
  <layout>
    <!-- 顶部操作 -->
    <!-- <section slot="search">
      <custom-form
        ref="search-form"
        class="search-form"
        v-model="tableSearch"
        layout="inline"
        mode="search"
        :FormList="searchColumns"
      >
        <a-button
          class="action-button"
          type="primary"
          icon="search"
          @click="search()"
          >搜索</a-button
        >
        <a-button class="action-button" type="primary" @click="handlerTableAdd"
          >新增农户</a-button
        >
      </custom-form>
    </section> -->

    <!-- 产品列表 -->
    <a-table
      :dataSource="tableData"
      :columns="tableColumns"
      :rowKey="(record) => record.s_a_nam"
      :pagination="false"
      :loading="tableLoading"
      @change="handleTableChange"
      :customRow="customTableRow"
      class="table-total"
      :scroll="{
        y: tableClientHeight + 70,
        x: '100%',
      }"
      bordered
    >

      <template slot="is_used" slot-scope="row, record, index">
        {{record.is_used === 1 ? '已补贴' : '未补贴'}}
      </template>
    </a-table>

    <!-- 产品列表分页器 -->
    <!-- <a-pagination
      slot="paging"
      :pageSizeOptions="pageSizes"
      :total="total"
      showSizeChanger
      :show-total="showTotal"
      :pageSize="pageSize"
      v-model="currentPage"
      @showSizeChange="changePageSize"
      @change="changePage"
    >
    </a-pagination> -->

    <!-- 编辑产品数据 -->
    <a-modal
      :visible="visible"
      :title="visibleTitle"
      :width="500"
      centered
      @cancel="visible = false"
    >
      <custom-form
        ref="custom-form"
        class="custom-form"
        v-model="currentRow"
        :FormList="formColumns"
        :mode="formMode"
        v-bind="formItemLayout"
        layout="horizontal"
      ></custom-form>
      <section slot="footer">
        <a-button type="primary" @click="handleSubmit">提交</a-button>
      </section>
    </a-modal>
  </layout>
</template>

<script lang="ts">
import { Mixins, Component, Watch, Vue, Prop } from 'vue-property-decorator'
import EventsMixin from '@/mixin/events'
import { TableMixin, AuthMixin } from '@/mixin'

import { TableLayout } from '@/layouts'
import CustomForm from '@/components/src/Form'
import { PayUnitType } from '@/common/enum'
import { famerServices } from '@/common/services/famer'
import { userModule } from '@/store/modules/user'
import { cropMemberServices } from '@/common/services/crop-member'
import subsidyServices from '@/common/services/subsidy'

@Component({
  components: {
    Layout: TableLayout,
    CustomForm,
  },
})
export default class AdminList extends Mixins(
  EventsMixin,
  TableMixin,
  AuthMixin
) {
  @Prop({
    type: String,
  })
  public currentAreaId!: string

  public commonParams = {
    s_a_id: '',
  }

  get isLarge() {
    return userModule.isLarge
  }

  public hasTotalRow = false

  public isLocalSort = true

  // 产品列表搜索条件
  public tableSearch = {}

  // 产品列表表格信息
  public columns: ITable.IColumn[] = [
    {
      title: '农户姓名',
      dataIndex: 'member_nam',
      key: 'member_nam',
      width: 120,
    },
    {
      title: '农户身份证号',
      dataIndex: 'member_sfz',
      key: 'member_sfz',
      width: 180,
    },
    {
      title: '家庭住址',
      dataIndex: 's_a_nam_all',
      key: 's_a_nam_all',
      width: 180,
    },
    {
      title: '补贴状态',
      dataIndex: 'is_used',
      key: 'is_used',
      width: 180,
      scopedSlots: { customRender: 'is_used' },
    },
  ]

  public tableApi = {
    list: famerServices.getDeadMembersFrom,
    // add: famerServices.updateDeadMember,
    // edit: famerServices.updateDeadMember,
    // del: famerServices.delDeadMember,
    // exportExecl: cropMemberServices.exportCropMemberCount,
  }

  @Watch('currentAreaId', { immediate: true })
  public handlerCurrentAreaIdChange() {
    this.commonParams.s_a_id = this.currentAreaId
    this.getData()
  }

  public mounted() {}

  public async getData() {
    const res = await this.getTableList()
    this.tableData = res.data || []
  }

  public handlerTableAdd() {
    this.tableAdd()
    this.$nextTick(() => {
      this.currentRow = Object.assign(
        {},
        { s_a_id: this.currentAreaId, role: 1 }
      )
    })
  }

  // 编辑前数据预处理
  public async handleTableEdit(row: any) {
    this.tableEdit(Object.assign({}, row))
  }
}
</script>

<style scoped lang="less">
.action-button {
  margin: 0px 10px 0px 10px;
}
.form-item-class {
  margin-bottom: 0px;
}
.img-box {
  width: 100px;
  height: 100px;
  margin: 10px;
}
.item-blue {
  color: #1989fa;
}
/deep/ .ant-table {
  th[key='member_total'],
  th[key='plant'],
  th[key^='pay'],
  th[key='pay_price_total'] {
    text-align: center !important;
  }

  thead tr {
    background: #fafafa;
  }

  tbody tr {
    background: #fff;
  }

  th[key='s_a_nam'],
  tr td:nth-of-type(3) {
    position: sticky;
    left: 0;
    z-index: 3;
    background: inherit;
  }
}
// /deep/ .ant-table-thead th {
//   text-align: center!important;
// }
</style>
